﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.Model;
using Hangjing.SQLServerDAL;
using Hangjing.Common;
using Hangjing.WebCommon;

public partial class deliverreg : System.Web.UI.Page
{
    Deliver userBLL = new Deliver();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.HttpMethod.ToUpper() == "POST")//获取post信息，提交订单
        {
            add_Click();
        }
        else {
            WebUtility.BindList("cid", "cname", CacheHelper.GetCityList(), ddlcity);
        }
    }

    /// <summary>
    /// 提交注册订单
    /// </summary>
    protected void add_Click()
    {
        string tbphone = WebUtility.InputText(Request["tbmobile"]);
        string tbGsmCode = WebUtility.InputText(Request["tbGsmCode"]);//验证码
        string tbname = WebUtility.InputText(Request["tbname"]);


        this.tbmobile.Value = tbphone;
        if (Session["gsmcode"] == null || Session["gsmcode"].ToString() != tbGsmCode.Trim())
        {
            divError.InnerHtml = "短信验证码错误！";
            return;
        }

        string sql = "Phone = '" + tbphone + "'";
        int count = userBLL.GetCount(sql);
        if (count > 0)
        {
            divError.InnerHtml = "手机号码重复了，请重新输入！";
            return;
        }


        DeliverInfo info = new DeliverInfo();
        info.CodeId = "0";
        info.Status = 0;
        info.Section = "试用";
        info.Name = WebUtility.InputText(tbname);
        info.Phone = WebUtility.InputText(tbphone);
        info.GpsIMEI = "0";
        info.OrderNum = 0;
        info.UserName = "";
        info.Password = "";
        info.Inve2 = "";
        info.Inve1 = Convert.ToInt32(WebUtility.InputText(Request["ddlcity"]));
        info.AddDate = DateTime.Now;

        info.workstate = 0;
        info.cartype = "电动车";
        info.carower = 0;
        info.carnum = "";
        info.post = 90;
        info.grade = 1;
        info.reveint1 = 0;
        info.reveint2 = 0;
        info.reveint3 = 0;
        info.revevar1 = "未交";
        info.revevar2 = "";
        info.revevar3 = "0";
        info.revefloat1 = 0;
        info.revefloat2 = 0;
        info.revedate = Convert.ToDateTime("1970-1-1");

        info.reveint4 = 0;
        info.reveint5 = 0;
        info.reveint6 = 0;
        info.revevar4 = "";
        info.revevar5 = "";
        info.revefloat3 = 0;
        info.revefloat4 = 0;



        OperateLogManager<DeliverInfo> logmanager = new OperateLogManager<DeliverInfo>("用户注册", TableENUM.Deliver.ToString());

        //操作日志
        deliverlogInfo item = new deliverlogInfo();
        item.admin = logmanager.adminname;
        item.optime = DateTime.Now;
        item.eventname = "添加";
        item.columntext = info.Name;
        item.columnname = "Name";
        item.oldvalue = "";
        item.newvalue = "";
        item.reveint1 = info.Inve1;
        item.reveint2 = 0;
        item.revevar1 = info.Name;
        item.revevar2 = TableENUM.Deliver.ToString();
        new deliverlog().Add(item);

        info.DataId = userBLL.Add(info);

        if (info.DataId > 0)
        {

            deliverInformationInfo otherinfo =  new deliverInformationInfo();
            otherinfo.deliverid = info.DataId;
            otherinfo.address = "";
            otherinfo.Marriage = "";
            otherinfo.homeaddress = "";
            otherinfo.Nation = "";
            otherinfo.QQ = "";
            otherinfo.Education = "";
            otherinfo.Emergency = "";
            otherinfo.Emergencyphone = "";
            otherinfo.Entrytime = "";
            otherinfo.Salarycard = "";
            otherinfo.Bank = "";
            otherinfo.workexperience = "";
            otherinfo.Reward = "";
            otherinfo.Complaint = "";
            otherinfo.Bond = 0;
            otherinfo.age = 0;
            otherinfo.reveint1 = 0;
            otherinfo.reveint2 = 0;
            otherinfo.reveint3 = "0";
            otherinfo.revevar1 = "";
            otherinfo.revevar3 = "";
            otherinfo.revedate1 = Convert.ToDateTime("1970-1-1");
            otherinfo.remark = "";
            otherinfo.revevar2 = "";

            new deliverInformation().Add(otherinfo);


            string url = "deliverreg.aspx?msg=200&id="+info.DataId;
            Response.Redirect(url);
        }
        else
        {
            string url = "deliverreg.aspx?msg=201";
            Response.Redirect(url);
        }

    }
}
